use std::any::Any;
use std::fmt::Debug;
use std::future::Future;

use aspect_codec::Codec;

use super::errors::*;
use super::state;

/// Describes a job type at a high level.
pub trait Job: Sync + Send + Any {
    /// Job payload type.
    type Payload: Codec + Debug + Sync + Send;

    /// Job type name.  Corresponds to `queue_name` database field.
    fn type_name(&self) -> &str;

    /// Executes a job payload.
    fn exec_job_payload(
        &self,
        job_meta: &state::JobMeta,
        payload: &Self::Payload,
    ) -> impl Future<Output = Result<(), JobError>> + Sync + Send;
}
